<?php
namespace Common\Model;
use Common\Model\CommonModel;
class RoleModel extends CommonModel{
	
	//自动验证
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('name', 'require', '角色名称不能为空！', 1, 'regex', CommonModel:: MODEL_BOTH ),
	);
	
	protected $_auto = array(
			array('create_time','time',1,'function'),
			array('update_time','time',2,'function'),
				
	);
	
	protected function _before_write(&$data) {
		parent::_before_write($data);
	}

	//查看 role_id
	public function role_id_get($role_str,$admin_id){
		$role = M("vradmin1.role", null);
		$roles = $role->field("role_id")->where("role_name in (".$role_str.")") ->select();
		$roles = implode(',', i_array_column($roles, "role_id"));

		$admin_role = M("vradmin1.admin_role",null);
		$admins = $admin_role->where("admin_id = ".$admin_id." and role_id in (".$roles.")")->select();

		if($admins){
			return 1;
		}else{
			return 0;
		}
	}

}